package com.xxmassdeveloper.mpchartexample;

import android.graphics.Color;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;

import java.util.ArrayList;
import java.util.List;

public class LineChartSampleActivity extends AppCompatActivity {

    private LineChart lineChart;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_linechart_sample);
        lineChart=findViewById(R.id.lc_data);
        XAxis xAxis = lineChart.getXAxis();
        xAxis.setTextSize(11f);
        xAxis.setTextColor(Color.WHITE);
        xAxis.setDrawGridLines(false);
        xAxis.setDrawAxisLine(false);

        YAxis leftAxis = lineChart.getAxisLeft();
        lineChart.getAxisRight().setEnabled(false);
        leftAxis.setAxisLineColor(Color.RED);
        leftAxis.setTextColor(ColorTemplate.getHoloBlue());
        leftAxis.setDrawGridLines(true);
        leftAxis.setGranularityEnabled(true);

        lineChart.animateX(500);
        lineChart.getLegend().setEnabled(false);

        List<Entry> entryList=new ArrayList<>();
        entryList.add(new Entry(0,1f));
        entryList.add(new Entry(1,2f));
        entryList.add(new Entry(2,Float.NaN));
        entryList.add(new Entry(3,11f));
        entryList.add(new Entry(4,3f));
        entryList.add(new Entry(5,4f));
        entryList.add(new Entry(6,Float.NaN));
        entryList.add(new Entry(7,2.6f));
        entryList.add(new Entry(8,1.55f));
        entryList.add(new Entry(9,8f));
        entryList.add(new Entry(10,7.2f));
        entryList.add(new Entry(11,6.6f));
        entryList.add(new Entry(12,Float.NaN));
        entryList.add(new Entry(13,Float.NaN));
        entryList.add(new Entry(14,9.3f));
        entryList.add(new Entry(15,4.8f));
        entryList.add(new Entry(16,5.8f));
        entryList.add(new Entry(17,Float.NaN));
        entryList.add(new Entry(18,Float.NaN));
        entryList.add(new Entry(19,13.5f));
        entryList.add(new Entry(20,1f));
        LineDataSet lineDataSet=new LineDataSet(entryList,"");
        lineDataSet.setColor(Color.RED);
        lineDataSet.setCircleColor(Color.RED);
        lineDataSet.setLineWidth(1f);
        lineDataSet.setCircleRadius(1f);

        LineData data = new LineData(lineDataSet);
        data.setValueTextColor(Color.WHITE);
        data.setValueTextSize(9f);
        lineChart.setData(data);
    }
}
